﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebSoftSeo.Models;

namespace WebSoftSeo.Controllers
{
    public class NewsController : Controller
    {
        WebSoftSeoEntities db = new WebSoftSeoEntities();
        //
        // GET: /News/

        public ActionResult Index(int page=0)
        {
            int skip=0;
            if (page != 0)
            {
                skip =2 * (page-1);
            }

            int count = db.News.Where(m=>m.IsBanner==false || m.IsBanner== null).ToList().Count();
            ViewBag.count = count;
            News news = db.News.Where(m => m.IsBanner == true).FirstOrDefault();
            ViewBag.Banner = news;
            var NewsIndex = db.News.OrderByDescending(m => m.CreatedDate).Where(m=>m.IsBanner == null || m.IsBanner ==false).Skip(skip).Take(2).ToList();
            ViewBag.NewsIndex = NewsIndex;
            var LastNews = db.News.OrderByDescending(m => m.CreatedDate).Where(m => m.IsBanner == null || m.IsBanner == false).Skip(2).Take(4).ToList();
            ViewBag.LastNews = LastNews;
            var PopularArticles = db.News.OrderByDescending(m => m.CreatedDate).Where(m => m.IsBanner == null || m.IsBanner == false).Skip(6).Take(8).ToList();

            return View(PopularArticles);
        }
        public ActionResult Detail(string title, int id = 0 )
        {
            News Banner = db.News.Where(m => m.IsBanner == true).FirstOrDefault();
            ViewBag.Banner = Banner;
            var LastNews = db.News.OrderByDescending(m => m.CreatedDate).Where(m => m.IsBanner == null || m.IsBanner == false).Skip(2).Take(4).ToList();
            ViewBag.LastNews = LastNews;
            var PopularArticles = db.News.OrderByDescending(m => m.CreatedDate).Where(m => m.IsBanner == null || m.IsBanner == false).Skip(6).Take(8).ToList();
            News news = db.News.Find(id);
            ViewBag.news = news;
            //if (!string.IsNullOrWhiteSpace(title))
            //{
 
            //}
            return View(PopularArticles);
        }
    }
}
